﻿using Daitto.Entity;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using SharpDX.Direct3D11;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using WpfAppTest.Views;

namespace WpfAppTest.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        public string BContent = "BBB";
        public string TEST2c
        {
            get { return BContent; }
            set { SetProperty(ref BContent, value); }
        }
        private DelegateCommand<string> _faceImgShowConLoadedcmd;

        public DelegateCommand<string> AAF =>
        _faceImgShowConLoadedcmd ?? (_faceImgShowConLoadedcmd = new DelegateCommand<string>(
        (p) =>
        {
            //TEST2c = "CCC";
                _Class1Test2.setL();
            _Class1Test2.tClassTest.Locations = "mmmmmmmmmmmmmmmm";
            MessageBox.Show(_Class1Test2.tClassTest.Content);

        }));

        private DelegateCommand<string> _BBF;

        public DelegateCommand<string> BBF =>
        _BBF ?? (_BBF = new DelegateCommand<string>(
        (p) =>
        {
           History history = new History();
           history.Show();   
        }));
        bool bb;
        private readonly IClass1Test2<ClassTest> _Class1Test2;
        private ClassTest _tClassTest;
        public ClassTest tClassTest
        {
            get { return _tClassTest; }
            set { SetProperty(ref _tClassTest, value); }
        }
        //重点看，页面加载时触发函数
        private DelegateCommand<string> _faceMainLoadedcmd;
        public DelegateCommand<string> FaceMainLoadedcmd =>
        _faceMainLoadedcmd ?? (_faceMainLoadedcmd = new DelegateCommand<string>(
        (p) =>
        {
            tClassTest = _Class1Test2.tClassTest;
        }));
        public MainWindowViewModel(IRegionManager regionManager, IClass1Test2<ClassTest> class1Test2)
        {
            _Class1Test2 = class1Test2;
            _Class1Test2.init();

            regionManager.RegisterViewWithRegion("Test2Region", typeof(Test2));
            Trace.WriteLine(bb);
            // 使用 MyCallbackMethod 作为回调函数
            MyCallback callback = MyCallbackMethod;
            ExecuteCallback(callback);

            // 或者可以使用匿名方法或 lambda 表达式
            ExecuteCallback(msg => Trace.WriteLine("Lambda callback received: " + msg));
        }
        // 定义一个委托，表示回调函数的签名
        public delegate void MyCallback(string message);
        public void ExecuteCallback(MyCallback callback)
        {
            // 在这里可以执行一些操作
            Trace.WriteLine("Executing some operations...");

            // 调用回调函数
            callback("Operation completed successfully!");
        }
        public static void MyCallbackMethod(string message)
        {
            Trace.WriteLine("Callback received: " + message);
        }
   
    }
}
